package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/26 18:48
 **/
public class Offer63 {
    class Solution {
        public int maxProfit(int[] prices) {
            if(prices.length <= 1) return 0;
            int ans = 0, minBuy = prices[0];
            for(int i = 1; i < prices.length; ++i){
                if(minBuy > prices[i]) minBuy = prices[i];
                else ans = Math.max(ans, prices[i] - minBuy);
            }
            return ans;
        }
    }
}